#include "Slingshot.h"

void Slingshot::Initialise(HDC* bHDC, LPSTR filename, int xpos, int ypos, int fWidth, int fHeight, 
	float sWidth, float sHeight, float animationSpeed, float movementSpeed, Input* myInput)
{
	AnimatedSprite::Initialise(bHDC, filename, xpos, ypos, fWidth, fHeight, sWidth, sHeight, animationSpeed, movementSpeed, 0, 0, false);
	input = myInput;
	xCentre = x + (width / 2);
	yCentre = y + (height / 2);
	mouseclicked = false;
	fired = false;
}

void Slingshot::Update()
{
	if (input->isLeftMouseDown() && input->getMouseX() >= x && input->getMouseX() <= x + width && input->getMouseY() >= y && input->getMouseY() <= y + height)
	{
		mouseclicked = true;
	}
	else if (input->isLeftMouseDown() && !mouseclicked)
	{
		input->SetLeftMouseUp();
	}

	if (mouseclicked && !input->isLeftMouseDown())
	{
		mouseX = input->getMouseX();
		mouseY = input->getMouseY();

		ToggleFired();
	}
	else if (mouseclicked)
	{
		mouseX = input->getMouseX();
		mouseY = input->getMouseY();
	}
}

void Slingshot::ToggleFired()
{
	if (fired == true)
		fired = false;
	else
		fired = true;
}